<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Slippy Map Tiles (3D Tiles Renderer)</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- Import maps polyfill -->
    <!-- Remove this when import maps will be widely supported -->
    <script async src="https://unpkg.com/es-module-shims@1.6.3/dist/es-module-shims.js"></script>

    <script type="importmap">
    {
        "imports": {
          "threepipe": "./../../dist/index.mjs",
          "@threepipe/plugin-3d-tiles-renderer": "./../../plugins/3d-tiles-renderer/dist/index.mjs"
        }
    }

    </script>
    <style id="example-style">
        html, body, #canvas-container, #mcanvas {
            width: 100%;
            height: 100%;
            margin: 0;
            overflow: hidden;
        }
    </style>
    <script type="module" src="../examples-utils/global-loading.mjs"></script>
    <script type="module" src="../examples-utils/simple-code-preview.mjs"></script>
    <script id="example-script" type="module" lang="ts">
        import {_testFinish, _testStart, LoadingScreenPlugin, ThreeViewer, SSAAPlugin} from 'threepipe'
        import {SlippyMapTilesLoadPlugin, EnvironmentControlsPlugin} from '@threepipe/plugin-3d-tiles-renderer'


        const viewer = new ThreeViewer({
            canvas: document.getElementById('mcanvas'),
            msaa: true, renderScale: window.devicePixelRatio,
            tonemap: false,
        })
        viewer.addPluginsSync([EnvironmentControlsPlugin, SlippyMapTilesLoadPlugin, LoadingScreenPlugin, SSAAPlugin])

        async function init() {

            viewer.scene.mainCamera.controlsMode = 'environment'
            viewer.scene.mainCamera.position.set(0,0, 200)
            viewer.scene.mainCamera.lookAt(0,0, 0)
            viewer.scene.mainCamera.minNearPlane = 0.1
            viewer.scene.mainCamera.setDirty()
            viewer.scene.mainCamera.controls.enableDamping = true
            viewer.scene.mainCamera.controls.minZoom = 0.1
            viewer.scene.mainCamera.controls.minDistance = 0.1
            viewer.scene.mainCamera.controls.maxDistance = 400
            viewer.scene.mainCamera.controls.cameraRadius = 1
            viewer.scene.mainCamera.controls.fallbackPlane.normal.set( 0,0 , 1 );
            viewer.scene.mainCamera.controls.up.set( 0, 0, 1 );

            // https://github.com/CesiumGS/3d-tiles-samples
            // from https://github.com/NASA-AMMOS/3DTilesRendererJS/blob/master/example/data/root.b3dm
            const result = await viewer.load('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
                autoCenter: true,
                autoScale: true,
                autoScaleRadius: 300,
                fileExtension: SlippyMapTilesLoadPlugin.DUMMY_EXT,
                tiles: {
                    errorTarget: 1,
                    XYZTilesPlugin: {
                        projection: 'planar',
                        center: true
                    },
                }
            })
            console.log(result)
            // result.rotation.x = - Math.PI / 2;
        }
        _testStart()
        init().finally(_testFinish)
    </script>
</head>
<body>
<div id="canvas-container">
    <canvas id="mcanvas"></canvas>
</div>

</body>
